﻿/*
培训任务的添加修改
*/
//
angular.module('addQuestionModel', ['vModal', 'loadModule', 'Common','interlocutionService'])
// 设置焦点 标签用
.directive('setFocus', function () {
     return function (scope, element) {
         element[0].focus();
     };
 })
 .directive("addQuestion", ["$rootScope", "$stateParams", "$timeout", "Msg","interlocutionservice", function ($rootScope, $stateParams, $timeout, Msg,IS) {
     return {
         restrice: "AE",
         scope: {
             item: "=",   // 保存对象
             editState:"=",//状态1审核  2编辑
             onClose: "&",    //关闭窗口       
             onSave: "&",      //保存对象到服务器                     
         },
         templateUrl: "/system/directive/interlocution/add_question.html",
         link: function (scope, element, attr) {
            scope.state=scope.item.state+"";
            scope.item.state=""+scope.item.state;
            //查询该问答关联的分类
            scope.getClass = function () {
                IS.findClassByQuesId({ quesid: scope.item.qaid }).then(function (response) {
                    if (response.errorcode == "0") {
                        scope.classList = response.datas;
                    } else {
                        Msg.error("查询分类失败!")
                    }
                }, function errorCallback() {
                    console.log("连接服务器失败！");
                });
            }
            //获取分类
             scope.getClass(); 
            // 保存
            scope.saveObj = function(){
                if(scope.item.title.length<=0){
                    Msg.warning("提示","请输入问答标题");
                    return;
                }
                scope.onSave();
            }
            scope.isHideFun=function(){
                scope.onClose();
            }
         }
     }
 } ]);
